<template>
  <el-form
    ref="userForm"
    :model="userInfo"
    label-width="120px"
    style="margin-left: 120px; margin-top: 30px"
  >
    <el-form-item label="姓名:">
      <el-input v-model="userInfo.username" style="width:300px" />
    </el-form-item>
    <el-form-item label="密码:">
      <el-input disabled v-model="userInfo.password" type="password" style="width:300px" />
    </el-form-item>
 
    <el-form-item>
      <el-button type="primary" @click="updateEmployees">更新</el-button>
    </el-form-item>
 </el-form>
</template>
<script>
import { getUserDetailById } from '@/api/user'
import { assEmployees } from '@/api/empioyees'
  export default {
    props:{
        id:{
            type:String,
            required:true
        }
    },
    data() {
        return {
            // 请求参数
            
          userInfo: {
              username: '',
              password: ''
            }
        }
      },
      created(){
        this.loadUserDetailById()
      },
      methods:{

        
        // 获取员工信息
        async loadUserDetailById(){
        
          try {
            const res = await getUserDetailById(this.id)
            this.userInfo=res.data
            // console.log('getUserDetailById', res)
            // 保存数据
          } catch (err) {
            console.log('getUserDetailById', err)
          }
        },
        // 修改员工信息
        async updateEmployees(){
          try {
            const res = await assEmployees(this.userInfo)
            this.$router.back()
            console.log('assEmployees', res)
            // 保存数据
          } catch (err) {
            console.log('assEmployees', err)
          }
        },
      }
  }
</script>
